﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SGX
{
    class SceneNode : IDisposable
    {
        string Name { get; set; }
        EffectState m_EffectState;
        List<SceneNode> m_children;

        public SceneNode(string name = "")
        {
            m_children = new List<SceneNode>();
            Name = name;
            m_EffectState = null;
        }

        public EffectState GetorCreateEffectState()
        {
            if (m_EffectState == null)
            {
                m_EffectState = new EffectState();
            }
            return m_EffectState;
        }
        virtual public void RenderChildren(Scene scene)
        {
            foreach (var node in m_children)
            {
                node.PreRender(scene);
                node.Render(scene);
                node.RenderChildren(scene);
                node.PostRender(scene);
            }
        }

        virtual public void Update(Scene scene, float dt)
        {}

        virtual public void PreRender(Scene scene)
        {}

        virtual public void Render(Scene scene)
        {}
        virtual public void PostRender(Scene scene)
        {}

        virtual public void Dispose()
        {
            foreach (var node in m_children)
            {
                node.Dispose();
            }
        }

        public void AddChild(SceneNode node)
        {
            m_children.Add(node);
        }
        public void RemoveChild(SceneNode node)
        {
            m_children.Remove(node);
        }
    }
}
